
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package doghost.utils;

import java.math.BigDecimal;
import org.jdesktop.beansbinding.Converter;


/**
 *
 * @author duo
 */
public class CustomFormattedDoubleConverter extends Converter {

    @Override
    public Object convertForward(Object value) {
        return value;
    }

    @Override
    public Object convertReverse(Object value) {
        if (value == null) {
            if (value instanceof BigDecimal) {
                return new BigDecimal(new Double("0.00"));
            } else {
                return new Double("0.00");
            }
        } else {
            if (value instanceof BigDecimal) {
                Double d = new Double(value.toString());
                BigDecimal bd = new BigDecimal(d);
                return bd;
            } else {
                Double d = new Double(value.toString());
                return d;

            }
        }
    }
}
